package com.config;

import com.util.GzhServiceUtil;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class WxMpConfig {

    @Autowired
    private GzhConfig gzhConfig;

    @Bean
    public WxMpConfigStorage wxMpConfigStorage(){
        WxMpInMemoryConfigStorage config = new WxMpInMemoryConfigStorage() ;
        config.setAppId(gzhConfig.getAppId()); // 设置微信公众号的appid
        config.setSecret(gzhConfig.getAppSecret()); // 设置微信公众号的app corpSecret
        config.setToken(gzhConfig.getToken()); // 设置微信公众号的token
        config.setAesKey(gzhConfig.getEncodingAESKey()); // 设置微信公众号的EncodingAESKey
        return config ;
    }


//    @Bean
//    public void wxMpService(WxMpConfigStorage config){
//        GzhServiceUtil instance = new GzhServiceUtil() ;
//        WxMpService wxMpService = new WxMpServiceImpl() ;
//        wxMpService.setWxMpConfigStorage(config);
//        GzhServiceUtil.put("test" , wxMpService);
//    }

    @Bean
    public GzhServiceUtil wxMpService1(){
        GzhServiceUtil instance = new GzhServiceUtil() ;
        WxMpInMemoryConfigStorage config = new WxMpInMemoryConfigStorage() ;
        config.setAppId(gzhConfig.getAppId()); // 设置微信公众号的appid
        config.setSecret(gzhConfig.getAppSecret()); // 设置微信公众号的app corpSecret
        config.setToken(gzhConfig.getToken()); // 设置微信公众号的token
        config.setAesKey(gzhConfig.getEncodingAESKey()); // 设置微信公众号的EncodingAESKey
        WxMpService wxMpService = new WxMpServiceImpl() ;
        wxMpService.setWxMpConfigStorage(config) ;
        GzhServiceUtil.put("pay" , wxMpService);

        WxMpService wxMpService1 = new WxMpServiceImpl();
        wxMpService1.setWxMpConfigStorage(config);
        GzhServiceUtil.put("test" , wxMpService1);

//        System.out.println(GzhServiceUtil.get("test"));
        return instance ;
    }

}
